/*
 * @Author: 赵成功a 3063126760@qq.com
 * @Date: 2024-12-26 23:00:50
 * @LastEditors: 赵成功a 3063126760@qq.com
 * @LastEditTime: 2025-01-05 22:42:56
 * @FilePath: /linux-learning/Sharedmemory/Server.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"Init.hpp"
using namespace std;  
int main() {  
    Init init;
    int shmid = CreateShm();// 创建共享空间
    char* buffer = (char*) shmat(shmid, NULL, 0); // 挂接空间，用char*去访问这片空间  //Creshm()
    int fd=open(FIFE_PIPE,O_CREAT|O_WRONLY|O_APPEND);
    if(fd<0){
        log(Fatal,"Server open failed,error string:%s,error code:%d",strerror(errno),errno);
        exit(OPEN_ERR);
    }
    while (true) { 
        cout << "Server@ "; 
        fgets(buffer,4096,stdin);
        size_t size=write(fd,"c",1);
        if(size==0)
        {
            break;
        }
    }  
    shmdt(buffer); // 解除联系  
    shmctl(shmid, IPC_RMID, NULL); // 删除共享内存  
    return 0;  
}  